package com.lark.utils;

import com.lark.context.ApplicationContext;
import javafx.geometry.Rectangle2D;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.layout.Background;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import static com.lark.context.ApplicationContext.SHOW_STACK_PANE;

public final class StageUtil {

    public static Stage show(Node node) {
        Rectangle2D bounds = Screen.getPrimary().getBounds();
        // 没有任务栏窗体
        Stage noTaskStage = new Stage();
        noTaskStage.setScene(new Scene(new StackPane()));
        noTaskStage.setX(Double.MAX_VALUE);
        noTaskStage.initStyle(StageStyle.UTILITY);
        noTaskStage.show();
        // 透明窗体
        Stage stage = new Stage();
        stage.initOwner(noTaskStage);
        SHOW_STACK_PANE = new StackPane(node);
        SHOW_STACK_PANE.setBackground(Background.fill(Color.TRANSPARENT));
        SHOW_STACK_PANE.setCursor(Cursor.HAND);
        Scene scene = new Scene(SHOW_STACK_PANE);
        stage.setScene(scene);
        scene.setFill(null);
        stage.initStyle(StageStyle.TRANSPARENT);
        stage.setAlwaysOnTop(true);
        stage.setWidth(800);
        stage.show();
        stage.setX(bounds.getWidth() - 300);
        stage.setY(10);
        return stage;
    }
}
